
/**
 * <a-button v-if="$auth('form.edit')">Button</a-button>
 * @param Vue
 */
function plugin(Vue) {
  if (plugin.installed) {
    return
  }

  !Vue.prototype.$auth && Object.defineProperties(Vue.prototype, {
    $auth: {
      get() {
        const _this = this
        return (permissions) => {
          const [permission,action] = permissions.split('.')
          const permissionList = Object.keys(_this.$store.getters.userInfo.permissions)
          return permissionList.find((val) => {
            if(val === permission){
              return true
            }else{
              return false
            }
          })
        }
      }
    }
  })
}

export default plugin
